<@app.html>
    <@app.head>
    <script>
        $(function () {
            $('#page_table').datagrid({
                fit: true,
                width: '100%',
                height: '100%',
                striped: true,
                pagination: true,
                url: "${contextPath}/security/basic/agent/page.htm",
                fitColumns: true,
                pageSize: 10,
                pageList: [10, 50, 100],
                idField: 'id',
                singleSelect: true,
                selectOnCheck: false,
                checkOnSelect: false,
                autoRowHeight: false,
                rowStyler: gridRowStyler,
                columns: [
                    [
                        {
                            title: '运营商名称',
                            align: 'center',
                            field: 'agentName',
                            width: 60
                        },
                        // {
                        //     title: '上级运营商',
                        //     align: 'center',
                        //     field: 'parentIdName',
                        //     width: 60
                        // },
                        {
                            title: '账户余额(元)',
                            align: 'center',
                            field: 'balance',
                            width: 60,
                            formatter: function (val) {
                                if(val!=null){
                                    return val/100
                                }else{
                                    return 0.00
                                }
                            }
                        },
                        {
                            title: '负责人姓名',
                            align: 'center',
                            field: 'principalName',
                            width: 40
                        },
                        {
                            title: '联系电话',
                            align: 'center',
                            field: 'tel',
                            width: 40
                        },
                        {
                            title: '详细地址',
                            align: 'center',
                            field: 'detailAddress',
                            width: 100
                        },
                        {
                            title: '状态',
                            align: 'center',
                            field: 'activeFlag',
                            width: 40,
                            formatter: function (val, row) {
                                return val == 1 ? '<p style="color:limegreen">'+'启用'+'</p>' : '<p style="color:red">'+'禁用'+'</p>'
                                <#--'<p style="green">'+'启用'+'</p>'-->
                            }
                        },
                        {
                            title: '操作',
                            align: 'center',
                            field: 'id',
                            width: 100,
                            formatter: function (val, row) {
                                var html = '<a href="javascript:view(ID)">查看</a>';
                                <@app.has_oper oper_code='1_1_3'>
                                    html += ' <a href="javascript:edit(ID)">修改</a>'
                                </@app.has_oper>
                                <@app.has_oper oper_code='1_1_4'>
                                if(row.activeFlag==1){
                                    html += ' <a href="javascript:disable(ID,0)">禁用</a>'
                                }else{
                                    html += ' <a href="javascript:disable(ID,1)">启用</a>'
                                }
                                </@app.has_oper>
                                <@app.has_oper oper_code='1_1_5'>
                                    html += ' <a href="javascript:remove(ID)">删除</a>'
                                </@app.has_oper>
                                return html.replace(/ID/g, row.id);
                            }
                        }
                    ]
                ],
                queryParams: {},
                onLoadSuccess: function () {
                    $('#page_table').datagrid('clearChecked');
                    $('#page_table').datagrid('clearSelections');
                }
            });
        })


        function reload() {
            var datagrid = $('#page_table');
            datagrid.datagrid('reload');
            var tree = $('#agent_tree');
            tree.tree('reload');
        }

        function query() {
            var tree = $('#agent_tree');
            var datagrid = $('#page_table');

            // var agentName = $('#agent_name').val();
            // var parentId = $('input[name="agentId"]').val();
            var id = $('input[name="agentId"]').val();
            datagrid.datagrid('options').queryParams = {
                id:id
                // agentName: agentName,
                // parentId: parentId
            };

            datagrid.datagrid('load');
        }
        function add() {
            App.dialog.show({
                css: 'width:660px;height:350px;overflow:visible;',
                title: '新建',
                href: "${contextPath}/security/basic/agent/add.htm",
                event: {
                    onClose: function () {
                        reload();
                    }
                }
            });
        }
        function edit(id) {
            App.dialog.show({
                css: 'width:380px;height:450px;overflow:visible;',
                title: '修改',
                href: "${contextPath}/security/basic/agent/edit.htm?id=" + id,
                event: {
                    onClose: function () {
                        var datagrid = $('#page_table');
                        datagrid.datagrid('reload');
                    },
                    onLoad: function () {
                    }
                }
            });
        }
        function view(id) {
            App.dialog.show({
                css: 'width:800px;height:520px;overflow:visible;',
                title: '查看',
                href: "${contextPath}/security/basic/agent/view.htm?id=" + id
            });
        }

        function disable(id,activeFlag) {
            $.messager.confirm('提示信息', '此操作将会影响该运营商下所有设备和用户?', function (ok) {
                if (ok) {
                    $.post("${contextPath}/security/basic/agent/disable.htm",{id:id,activeFlag:activeFlag},function (json) {
                        if (json.success) {
                            $.messager.alert('提示消息', '操作成功', 'info');
                            reload();
                        } else {
                            $.messager.alert('提示消息', json.message, 'info');
                        }
                    }, 'json');
                }
            });
        }
        function remove(id) {
            $.messager.confirm('提示信息', '此操作将会影响该运营商下所有设备和用户?', function (ok) {
                if (ok) {
                    $.post("${contextPath}/security/basic/agent/delete.htm",{id:id},function (json) {
                        if (json.success) {
                            $.messager.alert('提示消息', '操作成功', 'info');
                            reload();
                        } else {
                            $.messager.alert('提示消息', json.message, 'info');
                        }
                    }, 'json');
                }
            });
        }

        <#--function withdrawal(id) {-->
        <#--App.dialog.show({-->
        <#--css: 'width:433px;height:304px;overflow:visible;',-->
        <#--title: '提现',-->
        <#--href: "${contextPath}/security/basic/agent/withdrawal.htm?id=" + id,-->
        <#--event: {-->
        <#--onClose: function() {-->
        <#--var datagrid = $('#page_table');-->
        <#--datagrid.datagrid('reload');-->
        <#--},-->
        <#--onLoad: function() {-->
        <#--}-->
        <#--}-->
        <#--});-->
        <#--}-->
    </script>
    </@app.head>
    <@app.body>
        <@app.container>
            <@app.banner/>
        <div class="main">
            <@app.menu/>

            <div class="content">
                <div class="panel search">
                    <div class="float_right">
                        <#if Session['SESSION_KEY_USER'].type == Session['USER_TYPE_PLATFORM'].value>
                            <button class="btn btn_yellow" onclick="query()">搜索</button>
                        </#if>
                    </div>
                    <table cellpadding="0" cellspacing="0" border="0">
                        <tr>
                            <#if Session['SESSION_KEY_USER'].type == Session['USER_TYPE_PLATFORM'].value>
                                <td align="right">运营商：</td>
                                <td>
                                    <input name="agentId" class="easyui-combotree" editable="false"
                                           style="width: 184px; height: 28px;"
                                           data-options="url:'${contextPath}/security/basic/agent/tree.htm?dummy=${'所有'?url}',method:'get',onSelect: function(rec){
                               var url = '${contextPath}/security/hdw/agency/tree.htm?dummy=${'所有'?url}&agentId='+rec.id;
                               $('#agency_id').combotree('reload', url);},
                               onChange:function(){
                               $('#agency_id').combotree('clear');}"/>
                                </td>
                            </#if>
                            <#--<#if Session['SESSION_KEY_USER'].type == Session['USER_TYPE_AGENT'].value||Session['SESSION_KEY_USER'].type == Session['USER_TYPE_PLATFORM'].value>-->
                                <#--<td align="right">上级运营商：</td>-->
                                <#--<td>-->
                                    <#--<input name="agentId" class="easyui-combotree" editable="false"-->
                                           <#--style="width: 184px; height: 28px;"-->
                                           <#--data-options="url:'${contextPath}/security/basic/agent/tree.htm?agentId=<#if Session['SESSION_KEY_USER'].type == Session['USER_TYPE_AGENT'].value>${Session['SESSION_KEY_USER'].agentId}</#if>&dummy=${'无'?url}',method:'get'"/>-->
                                <#--</td>-->
                            <#--</#if>-->
                            <#--<td align="right">运营商名称：</td>-->
                            <#--<td><input type="text" class="text" id="agent_name"maxlength="20"/></td>-->
                        </tr>
                    </table>
                </div>
                <div class="panel grid_wrap">
                    <div class="toolbar clearfix">
                        <div class="float_right">
                            <@app.has_oper oper_code='1_1_2'>
                                    <button class="btn btn_green" onclick="add()">新建</button>
                                <#--<#if Session['SESSION_KEY_USER'].agencyId == 0&&Session['SESSION_KEY_USER'].supplierId == 0>-->
                                <#--</#if>-->
                            </@app.has_oper>
                        </div>
                        <h3>运营商信息</h3>
                    </div>
                    <div class="grid">
                        <table id="page_table"></table>
                    </div>
                </div>
            </div>
        </div>
        </@app.container>
    </@app.body>
</@app.html>